package zsc.nine.onlinemall.service;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.stereotype.Service;
import zsc.nine.onlinemall.entity.Feedback;
import zsc.nine.onlinemall.mapper.FeedbackMapper;

import java.util.Date;
import java.util.List;

@Component
public class FeedbackService {

    //创建反馈

    //删除反馈

    //更改反馈状态

    //查看所有(反馈)

    //用户查看自己所提交的所有反馈（前台调用）

    @Autowired
    FeedbackMapper feedbackMapper;

    //创建反馈
    public boolean addFeedback(String problem,String content,String userEmail,String userName){

        Feedback feedback = new Feedback();
        feedback.setId(0);
        feedback.setUserName(userName);
        feedback.setProblem(problem);
        feedback.setContent(content);
        feedback.setRead(false);
        feedback.setProblem(userEmail);
        feedback.setCreateDate(new Date(System.currentTimeMillis()));
        return feedbackMapper.addFeedback(feedback);
    }
    //删除反馈 ById
    public boolean deleteFeedback(int id){
       return feedbackMapper.deleteFeedbackById(id);
    }

    //更改反馈状态
    public boolean updateRead(int id,boolean b){
        return feedbackMapper.updateRead(id,b);
    }

    //查看所有(反馈)
    public List<Feedback>findAll(){
        return feedbackMapper.findAll();
    }

    //用户查看自己所提交的所有反馈（前台调用）
    public List<Feedback>findAllByEmail(String userEmail){
        return feedbackMapper.findAllByEmail(userEmail);
    }

}
